//
//  VKFansCell.m
//  V-Learn
//
//  Created by liubo on 2019/1/15.
//  Copyright © 2019 yxk. All rights reserved.
//

#import "VKFollowCell.h"

@implementation VKFollowCell{
    UIImageView *_imageV;
    UILabel *_titleLabel;

}

+ (instancetype)cellWithTableView:(UITableView *)tableView{
    VKFollowCell *cell = [tableView dequeueReusableCellWithIdentifier:@"VKFollowCell"];
    if (cell == nil) {
        cell = [[VKFollowCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"VKFollowCell"];
    }
    tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    return cell;
}
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // 点击cell的时候不要变色
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.backgroundColor = [UIColor whiteColor];
        
        // 布局子控件
        [self autoLayout];
    }
    return self;
}

-(void)setModel:(VKFansModel *)model{
    _titleLabel.text = model.username;
    [_imageV sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",Public_URL,model.headImg]] placeholderImage:[UIImage imageNamed:@"vkboy"]];
    if ([model.isAtten isEqualToString:@"1"]) {
        [self.rightBtn setTitle:@"取消关注" forState:UIControlStateNormal];
        self.rightBtn.layer.cornerRadius = 13;
        self.rightBtn.layer.masksToBounds = YES;
        self.rightBtn.backgroundColor = [UIColor whiteColor];
        [self.rightBtn setTitleColor:rgb(233,84,18) forState:UIControlStateNormal];
        self.rightBtn.layer.borderColor = rgb(233,84,18).CGColor;
        self.rightBtn.layer.borderWidth = 1;
    }else{
        [self.rightBtn setTitle:@"关注" forState:UIControlStateNormal];
        self.rightBtn.layer.cornerRadius = 13;
        self.rightBtn.layer.masksToBounds = YES;
        self.rightBtn.backgroundColor = rgb(233,84,18);
        [self.rightBtn setTitleColor:rgb(255,255,255) forState:UIControlStateNormal];
    }
}

- (void)autoLayout{
    
    UIImageView *arrowImageV = [[UIImageView alloc]init];
    arrowImageV.image = [UIImage imageNamed:@"vkboy"];
    [self.contentView addSubview:arrowImageV];
    _imageV = arrowImageV;
    arrowImageV.layer.cornerRadius = 25;
    arrowImageV.layer.masksToBounds = YES;
    [arrowImageV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.centerY.mas_equalTo(self.contentView);
        make.height.width.equalTo(@50);
    }];
    
    UILabel *titleLabel = [[UILabel alloc]init];
    _titleLabel = titleLabel;
    [self.contentView addSubview:titleLabel];
    titleLabel.text = @"小苹果";
    titleLabel.textColor = [UIColor cz_colorWithRed:62 green:62 blue:62];
    titleLabel.font = [UIFont systemFontOfSize:16];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(arrowImageV.mas_right).offset(10);
        make.centerY.mas_equalTo(self.contentView);
    }];
    
    UIView *lineView = [[UIView alloc]init];
    [self.contentView addSubview:lineView];
    lineView.backgroundColor = [UIColor cz_colorWithRed:244 green:244 blue:244];
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(@0);
        make.height.equalTo(@1);
        make.bottom.mas_equalTo(self.contentView);
    }];
    
    UIButton *rightBtn = [[UIButton alloc]init];
    _rightBtn = rightBtn;
    [self.contentView addSubview:rightBtn];
    rightBtn.backgroundColor = [UIColor whiteColor];//[UIColor cz_colorWithRed:235 green:80 blue:38];
    rightBtn.layer.cornerRadius = 13;
    rightBtn.layer.masksToBounds = YES;
    [rightBtn setTitle:@"取消关注" forState:UIControlStateNormal];
    [rightBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    rightBtn.titleLabel.font = [UIFont systemFontOfSize:13];
    [rightBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-10);
        make.centerY.mas_equalTo(self.contentView);
        make.width.equalTo(@80);
        make.height.equalTo(@26);
    }];
    
}

@end
